package com.whfc.common.vs.ezviz;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.whfc.common.exception.BizException;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultEnum;
import com.whfc.common.util.DateUtil;
import com.whfc.common.util.HttpUtil;
import com.whfc.common.util.JSONUtil;
import com.whfc.common.vs.ezviz.constant.EzvizConstant;
import com.whfc.common.vs.ezviz.entity.EzvizChannelInfo;
import com.whfc.common.vs.ezviz.entity.EzvizGbInfo;
import com.whfc.common.vs.ezviz.entity.EzvizRecordInfo;
import com.whfc.common.vs.ezviz.entity.EzvizStreamInfo;
import com.whfc.common.vs.ezviz.enums.EzvizDevicePtzStatus;
import com.whfc.common.vs.ezviz.enums.EzvizDeviceStatus;
import com.whfc.common.vs.ezviz.enums.EzvizResponseCode;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

import static com.whfc.common.vs.ezviz.constant.EzvizConstant.GB_LICENSE_LIST;

/**
 * @Description: 螢石云API
 * @author: likang
 * @version: 1.0
 * @date: 2021/3/2 10:37
 */
public class EzvizApi {

    private static final Logger logger = LoggerFactory.getLogger(EzvizApi.class);

    private static final String PROTOCOL_EZOPEN = "1";
    private static final String PROTOCOL_HLS = "2";
    private static final String PROTOCOL_RTMP = "3";
    private static final String PROTOCOL_FLV = "4";

    /**
     * ezopen协议前缀
     */
    private static final String EZVIZ_PROTOCOL_URL = "ezopen://open.ys7.com/";

    /**
     * 初始化token
     *
     * @param appKey    appKey
     * @param appSecret appSecret
     * @return token
     */
    public static String getAccessToken(String appKey, String appSecret) {
        try {

            Map<String, String> map = new HashMap<>(2);
            map.put("appKey", appKey);
            map.put("appSecret", appSecret);
            String resultStr = HttpUtil.doPost(EzvizConstant.ACCESS_TOKEN_URL, map);
            logger.info("萤石云获取AccessToken,appKey:{},response:{}", resultStr);
            Result result = JSON.parseObject(resultStr, Result.class);
            if (!result.getCode().equals(EzvizResponseCode.SUCCESS.getCode())) {
                logger.error("萤石云获取AccessToken失败,msg:{}", result.getMsg());
                throw new BizException(ResultEnum.FAILURE.getCode(), result.getMsg());
            }
            JSONObject jsonObject = (JSONObject) result.getData();
            return jsonObject.getString("accessToken");
        } catch (Exception ex) {
            logger.error("萤石云获取AccessToken出错", ex);
        }
        return null;
    }

    /**
     * 萤石云添加设备
     *
     * @param accessToken  授权过程获取的access_token
     * @param deviceSerial 设备序列号,存在英文字母的设备序列号，字母需为大写
     * @param validateCode 设备验证码，设备机身上的六位大写字母RF
     */
    public static void createDevice(String accessToken, String deviceSerial, String validateCode) {
        Map<String, String> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("deviceSerial", deviceSerial);
        map.put("validateCode", validateCode);
        String resultStr = "";
        try {
            resultStr = HttpUtil.doPost(EzvizConstant.CREATE_DEVICE_URL, map);
            logger.info("萤石云新增设备,deviceSerial:{},response:{}", deviceSerial, resultStr);
        } catch (Exception e) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "新增设备失败.");
        }
        Result result = JSON.parseObject(resultStr, Result.class);
        if (!EzvizResponseCode.EXISTS.getCode().equals(result.getCode()) &&
                !EzvizResponseCode.SUCCESS.getCode().equals(result.getCode())) {
            logger.warn("海康萤石云平台添加设备失败，deviceSerial:{},error{}", deviceSerial, result.getMsg());
            throw new BizException(ResultEnum.FAILURE.getCode(), result.getMsg());
        }

    }

    /**
     * 删除设备
     *
     * @param accessToken  授权过程获取的access_token
     * @param deviceSerial 设备序列号,存在英文字母的设备序列号，字母需为大写
     */
    public static void delDevice(String accessToken, String deviceSerial) {
        //从萤石云删除设备前，首先停止设备直播工作
        stopDevice(accessToken, deviceSerial);

        //然后删除设备
        Map<String, String> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("deviceSerial", deviceSerial);
        try {
            //删除设备
            String resultStr = HttpUtil.doPost(EzvizConstant.DELETE_DEVICE_URL, map);
            logger.info("萤石云删除设备,deviceSerial:{},response:{}", deviceSerial, resultStr);
            Result result = JSON.parseObject(resultStr, Result.class);
            if (!result.getCode().equals(EzvizResponseCode.SUCCESS.getCode())) {
                throw new BizException(ResultEnum.FAILURE.getCode(), result.getMsg());
            }
        } catch (Exception e) {
            logger.warn("萤石云删除设备失败,deviceSerial:{},error:{}", deviceSerial, e.getMessage());
            throw new BizException(ResultEnum.FAILURE.getCode(), "删除设备失败");
        }

    }

    /**
     * 获取设备状态
     *
     * @param deviceSerial 设备序列号
     * @return 设备状态
     */
    public static EzvizDeviceStatus getDeviceStatus(String accessToken, String deviceSerial) {
        Map<String, String> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("deviceSerial", deviceSerial);
        Integer status = 0;
        try {
            String resultStr = HttpUtil.doPost(EzvizConstant.DEVICE_INFO_URL, map);
            logger.debug("萤石云获取设备信息,accessToken:{},response:{}", accessToken, resultStr);
            Result result = JSON.parseObject(resultStr, Result.class);
            if (result.getCode().equals(EzvizResponseCode.SUCCESS.getCode()) && result.getData() != null) {
                status = ((JSONObject) result.getData()).getInteger("status");
            }
        } catch (Exception e) {
            logger.warn("萤石云获取设备信息失败,deviceSerial:{},error:{}", deviceSerial, e.getMessage());
        }
        return EzvizDeviceStatus.parseValue(status);
    }

    /**
     * 是否支持云台
     *
     * @param accessToken  accessToken
     * @param deviceSerial 设备序列号
     * @return 是否支持云台
     */
    public static EzvizDevicePtzStatus isSupportPtz(String accessToken, String deviceSerial) {
        Map<String, String> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("deviceSerial", deviceSerial);
        EzvizDevicePtzStatus status = EzvizDevicePtzStatus.NOT_SUPPORT_PTZ;
        try {
            String resultStr = HttpUtil.doPost(EzvizConstant.DEVICE_CAPACITY_URL, map);
            logger.info("获取设备能力集,deviceSerial:{},response:{}", deviceSerial, resultStr);
            Result result = JSON.parseObject(resultStr, Result.class);
            if (EzvizResponseCode.SUCCESS.getCode().equals(result.getCode()) && result.getData() != null) {
                JSONObject jsonObject = (JSONObject) result.getData();
                Integer supportPtz = jsonObject.getInteger(EzvizConstant.IS_SUPPORT_KEY);
                if (EzvizDevicePtzStatus.SUPPORT_PTZ.getValue().equals(supportPtz)) {
                    status = EzvizDevicePtzStatus.SUPPORT_PTZ;
                }
            }
        } catch (Exception e) {
            logger.warn("获取设备能力集失败,deviceSerial:{},error:{}", deviceSerial, e.getMessage());
        }
        return status;
    }

    /***
     * 萤石云开启云台操作
     * @param accessToken  accessToken
     * @param deviceSerial 设备序列号
     * @param  channelNo 非必选参数，不为空表示修改指定通道名称，为空表示修改通道1名称
     * @param direction 操作命令：0-上，1-下，2-左，3-右，4-左上，5-左下，6-右上，7-右下，8-放大，9-缩小，10-近焦距，11-远焦距
     */
    public static Boolean startPtz(String accessToken, String deviceSerial, Integer channelNo, Integer direction) {
        Boolean bool = false;
        Map<String, String> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("deviceSerial", deviceSerial);
        map.put("channelNo", channelNo == null ? "1" : String.valueOf(channelNo));
        map.put("direction", String.valueOf(direction));
        map.put("speed", "1");
        try {
            String resultStr = HttpUtil.doPost(EzvizConstant.START_PTZ_URL, map);
            logger.info("萤石云开启云台操作,response:{}", resultStr);
            Result result = JSON.parseObject(resultStr, Result.class);
            String code = result.getCode();
            if (EzvizResponseCode.SUCCESS.getCode().equals(code)) {
                //启动操作命令后，又停止云台，以防止一直操作
                stopPtz(accessToken, deviceSerial, channelNo, direction);
                bool = true;
            } else if (EzvizResponseCode.NOT_SUPPORT_PTZ.getCode().equals(code)
                    || EzvizConstant.DEVICE_OTHER_ERROR_CODE.equals(Integer.valueOf(code))) {
                logger.info(deviceSerial + " 设备不支持云台操作.");
            }
        } catch (BizException b) {
            throw new BizException(ResultEnum.FAILURE.getCode(), b.getMsg());
        } catch (Exception e) {
            logger.warn("萤石云开启云台操作失败,msg:{}", e.getMessage());
        }
        return bool;
    }

    /**
     * 萤石云停止云台操作
     *
     * @param accessToken  accessToken
     * @param deviceSerial 设备序列号
     * @param channelNo    通道号
     * @param direction    设备云台操作
     */
    public static void stopPtz(String accessToken, String deviceSerial, Integer channelNo, Integer direction) {

        Map<String, String> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("deviceSerial", deviceSerial);
        map.put("channelNo", channelNo == null ? "1" : String.valueOf(channelNo));
        map.put("direction", String.valueOf(direction));
        map.put("speed", "1");
        try {
            //先转动0.5s再停止
            Thread.sleep(500);
            //停止云台操作
            String resultStr = HttpUtil.doPost(EzvizConstant.STOP_PTZ_URL, map);
            logger.info("萤石云停止云台操作,response:{}", resultStr);
        } catch (Exception e) {
            logger.warn("萤石云停止云台操作失败,msg:{}", e.getMessage());
        }
    }

    /***
     * 抓取图片
     * @param accessToken  accessToken
     * @param deviceSerial 设备序列号
     * @param  channelNo 非必选参数，不为空表示修改指定通道名称，为空表示修改通道1名称
     * */
    public static String getSnapshotUrl(String accessToken, String deviceSerial, Integer channelNo) {
        Map<String, String> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("deviceSerial", deviceSerial);
        map.put("channelNo", channelNo == null ? "1" : String.valueOf(channelNo));
        String snapshotUrl = "";
        try {
            String resultStr = HttpUtil.doPost(EzvizConstant.GET_SNAPSHOT_URL, map);
            logger.debug("萤石云抓取图片,deviceSerial:{},channelNo:{},response:{}", deviceSerial, channelNo, resultStr);
            Result result = JSON.parseObject(resultStr, Result.class);
            if (result.getCode().equals(EzvizResponseCode.SUCCESS.getCode()) && result.getData() != null) {
                snapshotUrl = ((JSONObject) result.getData()).getString("picUrl");
            }
        } catch (Exception e) {
            logger.info("萤石云抓取图片失败,deviceSerial:{},channelNo:{},error:{}", deviceSerial, channelNo, e.getMessage());
        }
        return snapshotUrl;
    }

    /**
     * 获取当前用户直播地址列表
     *
     * @param accessToken
     * @param pageStart
     * @param pageSize
     * @return
     */
    public static String getStreamList(String accessToken, Integer pageStart, Integer pageSize) {
        Map<String, String> params = new HashMap<>(8);
        params.put("accessToken", accessToken);
        params.put("pageStart", String.valueOf(pageStart));
        params.put("pageSize", String.valueOf(pageSize));

        String response = HttpUtil.doPost(EzvizConstant.GET_VIDEO_LIST_URL, params);
        return response;
    }

    /**
     * 获取直播地址
     *
     * @param accessToken  accessToken
     * @param deviceSerial 设备序列号
     * @param channelNo    非必选参数，不为空表示修改指定通道名称，为空表示修改通道1名称
     */
    public static EzvizStreamInfo getStreamUrl(String accessToken, String deviceSerial, Integer channelNo) {
        return getHlsUrl(accessToken, deviceSerial, channelNo);
    }

    /**
     * 获取直播地址
     *
     * @param accessToken  accessToken
     * @param deviceSerial 设备序列号
     * @param channelNo    非必选参数，不为空表示修改指定通道名称，为空表示修改通道1名称
     * @param protocol     流播放协议，1-ezopen、2-hls、3-rtmp、4-flv，默认为1
     */
    public static EzvizStreamInfo getStreamUrl(String accessToken, String deviceSerial, Integer channelNo, String protocol) {
        EzvizStreamInfo streamInfo = new EzvizStreamInfo();
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, 7);
        streamInfo.setExpireTime(calendar.getTime());
        channelNo = channelNo == null ? 1 : channelNo;
        Map<String, String> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("deviceSerial", deviceSerial);
        map.put("channelNo", channelNo + "");
        //设置系请求的当前时间,为1周后的时间
        map.put("expireTime", String.valueOf(604800));
        //流播放协议，1-ezopen、2-hls、3-rtmp，默认为1
        map.put("protocol", protocol);

        //视频清晰度，1-高清（主码流）、2-流畅（子码流）
        //获取高清视频 hls 主码流
        map.put("quality", "1");
        streamInfo.setHlsHd(getStreamAddress(map));
        //获取 hls 子码流
        map.put("quality", "2");
        streamInfo.setHls(getStreamAddress(map));
        //拼接 ezopen 播放地址
        String ezopen = EZVIZ_PROTOCOL_URL + deviceSerial + "/" + channelNo;
        streamInfo.setEzopen(ezopen + ".live");
        streamInfo.setEzopenHd(ezopen + ".hd.live");
        //补全其他信息
        streamInfo.setDeviceSerial(deviceSerial);
        streamInfo.setChannelNo(channelNo);

        return streamInfo;

    }

    /**
     * 获取直播地址
     *
     * @param accessToken
     * @param deviceSerial
     * @param channelNo
     * @return
     */
    public static EzvizStreamInfo getRtmpUrl(String accessToken, String deviceSerial, Integer channelNo) {
        return getStreamUrl(accessToken, deviceSerial, channelNo, PROTOCOL_RTMP);
    }

    /**
     * 获取直播地址
     *
     * @param accessToken
     * @param deviceSerial
     * @param channelNo
     * @return
     */
    public static EzvizStreamInfo getEzopenUrl(String accessToken, String deviceSerial, Integer channelNo) {
        return getStreamUrl(accessToken, deviceSerial, channelNo, PROTOCOL_EZOPEN);
    }

    /**
     * 获取直播地址
     *
     * @param accessToken
     * @param deviceSerial
     * @param channelNo
     * @return
     */
    public static EzvizStreamInfo getHlsUrl(String accessToken, String deviceSerial, Integer channelNo) {
        return getStreamUrl(accessToken, deviceSerial, channelNo, PROTOCOL_HLS);
    }

    /**
     * 获取直播地址
     *
     * @param accessToken
     * @param deviceSerial
     * @param channelNo
     * @return
     */
    public static EzvizStreamInfo getFlvUrl(String accessToken, String deviceSerial, Integer channelNo) {
        return getStreamUrl(accessToken, deviceSerial, channelNo, PROTOCOL_FLV);
    }

    /**
     * 获取录像地址
     *
     * @param map 请求参数
     */
    private static String getStreamAddress(Map<String, String> map) {
        String url = "";
        try {
            String resultStr = HttpUtil.doPost(EzvizConstant.STREAM_PLAY_URL_V2, map);
            logger.info("获取直播地址,response{}", resultStr);
            Result result = JSON.parseObject(resultStr, Result.class);
            if (result.getCode().equals(EzvizResponseCode.OFFLINE.getCode())) {
                logger.warn("萤石云获取直播地址失败，msg:{}", result.getMsg());
                throw new BizException(ResultEnum.SUCCESS.getCode(), "设备处于离线状态");
            }
            if (!result.getCode().equals(EzvizResponseCode.SUCCESS.getCode())) {
                logger.warn("萤石云获取直播地址失败,msg:{}", result.getMsg());
                throw new BizException(ResultEnum.FAILURE.getCode(), "获取直播地址失败");
            }
            url = ((JSONObject) result.getData()).getString("url");
        } catch (BizException e) {
            logger.warn("萤石云获取直播地址失败,msg:{}", e.getMsg());
            throw new BizException(ResultEnum.FAILURE.getCode(), e.getMsg());
        }
        return url;
    }

    /**
     * 获取录像地址
     *
     * @param accessToken  accessToken
     * @param deviceSerial
     * @param channelNo
     * @param startTime
     * @param endTime
     */
    public static List<EzvizRecordInfo> getRecordList(String accessToken, String deviceSerial, Integer channelNo, Date startTime, Date endTime) {
        List<EzvizRecordInfo> recordList;

        Map<String, String> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("deviceSerial", deviceSerial);
        if (channelNo == null) {
            channelNo = 1;
        }
        map.put("channelNo", String.valueOf(channelNo));
        map.put("startTime", String.valueOf(startTime.getTime()));
        map.put("endTime", String.valueOf(endTime.getTime()));
        try {
            String resultStr = HttpUtil.doPost(EzvizConstant.GET_RECORD_URL, map);
            logger.info("萤石云获取录像,response:{}", resultStr);
            Result result = JSON.parseObject(resultStr, Result.class);
            if (!result.getCode().equals(ResultEnum.SUCCESS.getCode())) {
                logger.warn("萤石云获取录像信息失败,msg:{}", result.getMsg());
                throw new BizException(ResultEnum.FAILURE.getCode(), result.getMsg());
            }
            recordList = JSON.parseArray(String.valueOf(result.getData()), EzvizRecordInfo.class);
            if (recordList != null && !recordList.isEmpty()) {
                //拼接录像回放地址
                for (EzvizRecordInfo record : recordList) {
                    //萤石云回放拼接规则 ezopen://验证码@域名/序列号/通道号.回放源.rec?参数1=值&参数2=值
                    //示例 ： ezopen://open.ys7.com/440912260/1.local.rec?begin=yyyyMMddhhmmss&end=yyyyMMddhhmmss
                    String recType = "";
                    if (1 == record.getRecType()) {
                        recType = "cloud";
                    } else if (2 == record.getRecType()) {
                        recType = "local";
                    }
                    Date start = new Date(record.getStartTime());
                    Date end = new Date(record.getEndTime());
                    String pattern = "yyyyMMddHHmmss";
                    String startStr = DateUtil.formatDate(start, pattern);
                    String endStr = DateUtil.formatDate(end, pattern);
                    String url = EZVIZ_PROTOCOL_URL + record.getDeviceSerial()
                            + "/" + record.getChannelNo() + "." + recType + ".rec?begin=" + startStr
                            + "&end=" + endStr;
                    record.setRecordURL(url);
                }
            }
        } catch (Exception e) {
            logger.warn("获取回放记录失败", e);
            throw new BizException(ResultEnum.FAILURE.getCode(), "获取回放记录失败.");
        }
        return recordList;
    }

    /**
     * 获取通道列表
     *
     * @param accessToken  accessToken
     * @param deviceSerial
     */
    public static List<EzvizChannelInfo> getChannelList(String accessToken, String deviceSerial) {
        List<EzvizChannelInfo> channelInfoList = new ArrayList<>();

        Map<String, String> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("deviceSerial", deviceSerial);
        try {
            String resultStr = HttpUtil.doPost(EzvizConstant.GET_CAMERA_LIST_URL, map);
            logger.info("萤石云获取通道信息,response:{}", resultStr);
            Result result = JSON.parseObject(resultStr, Result.class);
            if (result.getCode().equals(ResultEnum.SUCCESS.getCode()) && result.getData() != null) {
                channelInfoList = JSONArray.parseArray(result.getData().toString(), EzvizChannelInfo.class);
                if (!channelInfoList.isEmpty()) {
                    //构造启动直播功能的通道号请求参数
                    StringBuilder channelNoSb = new StringBuilder();
                    for (EzvizChannelInfo channelInfo : channelInfoList) {
                        //获取通道号
                        Integer channelNo = channelInfo.getChannelNo();
                        //添加设备启动 source
                        channelNoSb.append(deviceSerial).append(":").append(channelNo).append(",");
                    }
                    String source = channelNoSb.toString();
                    if (StringUtils.isNotEmpty(source)) {
                        source = source.substring(0, source.length() - 1);
                    }
                    //启动设备的直播功能
                    startDevice(accessToken, source);
                }
            }
        } catch (Exception e) {
            logger.info("萤石云获取通道信息,error:{}", e.getMessage());
            throw new BizException(ResultEnum.FAILURE.getCode(), "创建设备失败.");
        }
        return channelInfoList;
    }

    /**
     * 视频解密
     *
     * @param accessToken  token
     * @param deviceSerial 设备序列号
     * @param password     验证码
     * @return 是否解密成功
     */
    public static Boolean deviceDecrypt(String accessToken, String deviceSerial, String password) {
        Map<String, String> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("deviceSerial", deviceSerial);
        map.put("validateCode", password);
        String resultStr = null;
        try {
            resultStr = HttpUtil.doPost(EzvizConstant.DEVICE_DECRYPT_URL, map);
            logger.info("萤石云设备解密,response:{}", resultStr);
        } catch (Exception e) {
            logger.info("萤石云设备解密失败,error:{}", e.getMessage());
        }
        if (StringUtils.isNotEmpty(resultStr)) {
            Result result = JSON.parseObject(resultStr, Result.class);
            if (result != null && result.getCode().equals(ResultEnum.SUCCESS.getCode()) && result.getData() != null) {
                logger.info("萤石云设备解密成功");
                return true;
            }
        }
        return false;
    }

    /**
     * 停止设备直播功能
     *
     * @param deviceSerial 设备序列号
     */
    public static void stopDevice(String accessToken, String deviceSerial) {
        Map<String, String> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("source", deviceSerial + ":1");
        try {
            String resultStr = HttpUtil.doPost(EzvizConstant.STOP_DEVICE_URL, map);
            logger.info("萤石云停止设备,response:{}", resultStr);
        } catch (Exception e) {
            logger.warn("萤石云停止设备,error:{}", e.getMessage());
        }
    }

    /**
     * 启动设备直播功能
     *
     * @param accessToken accessToken
     * @param source      source=设备序列号：通道号
     */
    public static void startDevice(String accessToken, String source) {
        Map<String, String> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("source", source);
        try {
            String resultStr = HttpUtil.doPost(EzvizConstant.START_DEVICE_URL, map);
            logger.info("萤石云启动设备,response:{}", resultStr);
        } catch (Exception e) {
            logger.warn("萤石云启动设备失败,error:{}", e.getMessage());
        }
    }

    /**
     * 获取国标设备列表
     *
     * @param accessToken
     * @param productKey
     * @return
     */
    public static List<EzvizGbInfo> getGbLicenseList(String accessToken, String productKey) {
        List<EzvizGbInfo> list = null;
        String url = GB_LICENSE_LIST;
        Map<String, String> param = new HashMap<>(2);
        param.put("accessToken", accessToken);
        param.put("productKey", productKey);
        String respone = HttpUtil.doPost(url, param);
        logger.info("获取国标设备列表,productKey:{},resposne:{}", productKey, respone);
        JSONObject resJson = JSONObject.parseObject(respone);
        if (resJson != null && resJson.containsKey("data")) {
            String data = resJson.getString("data");
            list = JSONUtil.parseArray(data, EzvizGbInfo.class);
            return list;
        }
        if (list == null) {
            list = Collections.EMPTY_LIST;
        }
        return list;
    }

}
